<?php
	/**
	 * 特殊字符的处理(文本框)
	 * @param string or array
	 * @return string or array
	 */
	function stringToHtml($str){
		$html = "";
		if(is_string($str))
		{
			$html = "";
			$html = htmlspecialchars($str);
		}
		else if(is_array($str))
		{
			$html = array();
			foreach($str as $key=>$value)
			{
				$keyNew = htmlspecialchars($key);
				$html[$keyNew] = $this->stringToHtml($value);
			}
		}
		else
		{
			$html = $str;
		}
		return $html;
	}
	
	/**
	 * 特殊字符处理(label)
	 * @param string or array
	 * @return string or array
	 */
	function labelStringToHtml($str){
		$html = "";
		if(is_string($str))
		{
			$html = "";
			$html = htmlspecialchars($str);
			$html = str_replace("\r\n", '<br>', $html);
			$html = str_replace("\n", '<br>', $html);
			$html = str_replace("\r", '<br>', $html);
			$html = str_replace(" ", '&nbsp;', $html);
		}
		else if(is_array($str))
		{
			$html = array();
			foreach($str as $key=>$value)
			{
				$keyNew = htmlspecialchars($key);
				$keyNew = str_replace("\r\n", '<br>', $keyNew);
				$keyNew = str_replace("\n", '<br>', $keyNew);
				$keyNew = str_replace("\r", '<br>', $keyNew);
				$keyNew = str_replace(" ", '&nbsp;', $keyNew);
				$html[$keyNew] = $this->labelStringToHtml($value);
			}
		}
		else
		{
			$html = $str;
		}
		return $html;
	}
?>